﻿//逻辑代码
import {Puerts} from 'csharp'
import {GameObjectPool} from "framework/common/GameObjectPool";
import {ResourcesMgr} from "framework/common/ResourcesMgr";
import((`framework/logger`))
//启动器，程序第一个启动的js脚本
class Launcher 
{
    constructor(behaviour: Puerts.JsManager) {
        behaviour._jsOnApplicationQuit = () => this.OnApplicationQuit();
        behaviour._jsDispose = () => this.OnDispose();
        behaviour._jsStart = ()=>this.Start();
        behaviour._jsOnDestroy = ()=>this.OnDestroy();
    }
    Start (){
        try{

            //启动单例
            GameObjectPool.Instance();

            // UIManager.Instance(UIManager);
            ResourcesMgr.Instance();

            //预加载excel数据
            //ExcelManager.Instance(ExcelManager);
            //
            // //do Unit Test
            // UnitTest.doTest();
            //
            // //进入登录模块
            // SceneManager.Instance(SceneManager).loadScene(SceneDef.LoginScene,()=>{});
            //
            //
            // //JS启动完成，通知C#层
            // GameLaunch.Instance.JsLuanchFinish();

        }catch(ex){
            console.error(ex);
        }
        console.log("Launcher started in JS....");
    }    
    OnDestroy() {
        console.log('Launcher onDestroy in JS...');
    }
    protected OnDispose() {

        console.log("Launcher onDispose in JS....");
    }

    protected OnApplicationQuit() {
        GameObjectPool.Instance().Cleanup(true);
        console.log("Launcher onApplicationQuit in JS....");
    }
}

export function init (jsBehavior:Puerts.JsManager) {
    require('framework/component').init(jsBehavior)
    new Launcher(jsBehavior);
}
